﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace FSC.HaNamAPApplication
{
    public partial class HNAP_AdminDocType : System.Web.UI.UserControl
    {
        public string CurrentUrlWithoutParam
        {
            get
            {
                return Controler.UrlWithoutParam(Request.RawUrl);
            }
        }

        protected int number = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            HaNamAPDataDataContext db = new HaNamAPDataDataContext(Controler.HaNamAPConnectionString);

            var data = from a in db.DocumentTypes
                       orderby a.DocType_ID descending
                       select new
                       {
                           ID = a.DocType_ID,
                           Name = a.Name,
                       };

            rptList.DataSource = data;
            rptList.DataBind();
        }

        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.ToString().Equals("Del"))
            {
                HaNamAPDataDataContext db = new HaNamAPDataDataContext(Controler.HaNamAPConnectionString);
                DocumentType obj = db.DocumentTypes.SingleOrDefault(a => a.DocType_ID == int.Parse(e.CommandArgument.ToString()));
                if (obj != null)
                {
                    db.DocumentTypes.DeleteOnSubmit(obj);
                    db.SubmitChanges();

                    BindData();
                }
            }
        }
    }
}